/**
 * 
 */
package com.swe727.spring2011.constraint1.node;

import java.util.HashSet;

import com.swe727.spring2011.constraint1.datastore.DataStore;
import com.swe727.spring2011.constraint1.message.Message;

public class NodeDataStore implements DataStore<Message<Node>, String> {
	
	private static final long serialVersionUID = 3817877716317790918L;
	private HashSet<Message<Node>> nodes;

	/**
	 * Singleton pattern so that multiple threads can access the data store
	 */
	private static NodeDataStore store;
	
	public static NodeDataStore getStore() {
		if (store == null) {
			store = new NodeDataStore();
		}
		
		return store;
	}
	
	/**
	 * Create a new data store for observations.
	 */
	private NodeDataStore() {
		nodes = new HashSet<Message<Node>>();
	}
	
	@Override
	public synchronized void add(Message<Node> data) {
		nodes.add(data);
	}

	@Override
	public synchronized HashSet<Message<Node>> getAll(String key) {
		return nodes;
	}
}
